//
//  ViewController.swift
//  瀑布流布局
//
//  Created by 我演示 on 2019/11/4.
//  Copyright © 2019 ALLSall. All rights reserved.
//

import UIKit

private let kContentCellID = "kContentCellID"

class ViewController: UIViewController {

    fileprivate lazy var collectionView: UICollectionView  = {
       let layout = FSLWaterfallLayout()
        layout.sectionInset = UIEdgeInsets(top: 10, left: 20, bottom: 10, right: 20)
        layout.minimumInteritemSpacing = 10
        layout.minimumLineSpacing = 10
        
        let collectionView = UICollectionView(frame: self.view.bounds, collectionViewLayout: layout)
        collectionView.dataSource = self
        collectionView.delegate = self
        
        return collectionView
        
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
        view.addSubview(collectionView)
        collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: kContentCellID)
    }


}


extension ViewController : UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 100
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kContentCellID, for: indexPath)
        cell.backgroundColor = UIColor.white
        
        return cell
    }
    
    
    
}
extension ViewController : UICollectionViewDelegate {
    
}

extension ViewController : FSLWaterfallLayoutDataSource {
    func numberOfCols(_ waterfallLayout: FSLWaterfallLayout) -> Int {
        return 2
    }
    
    func waterfall(_ waterfall: FSLWaterfallLayout, item: Int) -> CGFloat {
        return CGFloat(arc4random_uniform(150)  + 150 )
    }
    
    
    
}
